/**
 *
 */
package com.module.boots.coder.application;

import java.sql.SQLException;

import org.apache.velocity.VelocityContext;

import com.module.boots.coder.base.BaseCoder;
import com.module.boots.coder.utils.MysqlBeanUtils;
import com.module.boots.coder.utils.PageUtils;

/**
 * 生成前端系统控制器
 * @author：溪云阁
 * @date：2020年9月4日
 */
public class ApplicationCoder extends BaseCoder {

    /**
     * 生成application控制类
     * @author 溪云阁
     * @param tableName 表名
     * @throws SQLException void
     */
    public void createApplication() throws Exception {
        // 获取最基础的模板
        final VelocityContext context = getBaseContext(tableName);
        final String applicationPath = getBasePackagePath() + "/application/" + getUpperClassName(tableName).toLowerCase() + "/" + getUpperClassName(tableName) + "Application.java";
        PageUtils.WriterPage(context, "application/application.ftl", applicationPath);
    }

    /**
     * 创建application出参
     * @author 溪云阁
     * @param tableName 表名
     * @param aoName 出参类名称
     * @param aoDescription 出参类描述
     * @throws SQLException void
     */
    public void createAO(String aoName, String aoDescription) throws Exception {
        // 获取最基础的模板
        final VelocityContext context = getBaseContext(tableName);
        final String aoPath = getBasePackagePath() + "/application/" + getUpperClassName(tableName).toLowerCase() + "/ao/" + aoName + "AO.java";
        context.put("aoName", aoName);
        context.put("aoDescription", aoDescription);
        context.put("feilds", MysqlBeanUtils.getOutFeilds(tableName));
        context.put("importTypes", MysqlBeanUtils.getOutPacking(tableName));
        PageUtils.WriterPage(context, "application/ao.ftl", aoPath);
    }

    /**
     * 创建application入参
     * @author 溪云阁
     * @param tableName 表名
     * @param paoName 入参类名称
     * @param paoDescription 入参类描述
     * @throws SQLException void
     */
    public void createPAO(String paoName, String paoDescription) throws Exception {
        // 获取最基础的模板
        final VelocityContext context = getBaseContext(tableName);
        final String apoPath = getBasePackagePath() + "/application/" + getUpperClassName(tableName).toLowerCase() + "/pao/" + paoName + "PAO.java";
        context.put("paoName", paoName);
        context.put("paoDescription", paoDescription);
        context.put("feilds", MysqlBeanUtils.getInFeilds(tableName));
        context.put("importTypes", MysqlBeanUtils.getInPacking(tableName));
        PageUtils.WriterPage(context, "application/pao.ftl", apoPath);
    }

}
